package com.codemonkey.lq.common.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public final class DateHelper {
	private DateHelper() {
		throw new Error("Can not instantize ! ! !");
	}

	/**
	 * 被这些第三包里的Date类型坑成汪了...
	 */
	public static final String formatCurrentTime(String pattern) {
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
		return simpleDateFormat.format(new Date());

		// 格式化指定日志
		// "yyyy/MM/dd hh:mm:ss"
		// Date curDate = new Date();
		// String format = DateFormatUtils.format(curDate, pattern);
	}

	public static final Date getDateFromString(String dateStr, String pattern) {
		SimpleDateFormat sdf = new SimpleDateFormat(pattern);

		Date date = null;
		try {
			date = sdf.parse(dateStr);
		} catch (ParseException e) {
			//e.printStackTrace();

			//swallow the exception
		}

		return date;
	}
}
